package DAL;

import Entity.Journal;
import Entity.Reads;
import Utils.JDBCUtils;
import Utils.TSUtility;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.io.*;
import java.sql.Connection;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;
import java.util.jar.JarEntry;

/**
 * @Author Chen
 * @Date 2022/1/9 10:15
 * @Version 1.0
 */
public class LogDao {
    public static void main(String[] args) {
       /* Journal journal = new Journal();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入添加日志年份"+journal.getTime()+"：");
        int year= TSUtility.readInt_year();
        year=year-1900;
        System.out.println("请输入出版月份"+journal.getTime()+"：");
        int mouth=TSUtility.readInt_mouth();
        mouth=mouth-1;
        System.out.println("请输入出版日"+journal.getTime()+"：");
        int day=TSUtility.readInt_day();
        Date publicationDate=new Date(year,mouth,day);
        String job = "李明登录了图书管理系统";
        insertloginLog(publicationDate,job);*/

        System.out.println(showlogin());

    }
    //日志添加
    public static int insertloginLog(Object... args) {
        int result = 0;
        Connection conn = null;
        try {
            QueryRunner runner = new QueryRunner();
            conn = JDBCUtils.getConnection3();
            String sql = "insert into l_journal(time,jobContent)values(?,?)";

            result = runner.update(conn, sql, args);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.closeResource(conn, null);
        }
        return result;
    }


    //日志查询
    public static  List<Journal> showlogin()  {
        List<Journal> result = null;
        Connection conn = null;
        try {
            QueryRunner runner = new QueryRunner();
            conn = JDBCUtils.getConnection3();
            String sql = "select * from l_journal";
            BeanListHandler<Journal> handler = new BeanListHandler<>(Journal.class);
            result = runner.query(conn, sql, handler);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.closeResource(conn, null);
        }
        return result;

    }

}
